# -*- coding:utf-8 -*-
from django.db import models
from django.db.models import permalink
import datetime
import json
import time

# python manage.py makemigrations
# python manage.py migrate
# python manage.py syncdb
# python manage.py collectstatic

class Reporter(models.Model):
    full_name=models.CharField(max_length=70)

    class Meta:
        pass

    def __unicode__(self):
        return self.full_name


class DevModules(models.Model):

    moduleTypeList=(
        ("dev",u"开发包"),
        ("min",u"压缩包"),
        ("ent",u"加密包"),
    )

    project_name = models.CharField(max_length=60)
    project_version = models.DecimalField(max_digits=4, decimal_places=2, default="1.10")
    project_url = models.CharField(max_length=80)
    module_name = models.CharField(max_length=20)
    module_type = models.CharField(max_length=10,choices=moduleTypeList,default="dev")
    module_path = models.CharField(max_length=80)
    size = models.CharField(max_length=10)
    modify_time = models.DateTimeField(default=datetime.datetime.now);
    md5 = models.CharField(max_length=50)
    zip = models.CharField(max_length=20)
    notify = models.BooleanField(default=False)

    class Meta:
        ordering = ['-modify_time']

    def __unicode__(self):
        return self.project_name

    def toJSON(self):
        fields = []
        for field in self._meta.fields:
            fields.append(field.name)
        d = {}

        for attr in fields:
           d[attr] = getattr(self, attr)
        return json.dumps(d)

    def toDict(self):
        fields = []
        for field in self._meta.fields:
            fields.append(field.name)
        d = {}

        for attr in fields:
           d[attr] = getattr(self, attr)
        return d

class Article(models.Model):
    pub_Date=models.DateTimeField()
    headline=models.CharField(max_length=200)
    content=models.TextField()
    reporter=models.ForeignKey(Reporter)

    class Meta:
        pass

    def __unicode__(self):
        return self.headline


class Area(models.Model):
    Area_Level = (
         (0, u'全国'),
         (1, u'省、直辖市'),
         (2, u'市、直辖市区'),
         (3, u'区、县等'),
    )

    areaname = models.CharField(max_length=30,unique=True, verbose_name='区域名称')
    code = models.CharField(max_length=20,blank=True, default="", verbose_name='区域代码')
    parentid  = models.IntegerField(verbose_name='父级id', null=True)
    level = models.IntegerField(choices=Area_Level,verbose_name='层级', null=True)


